# this script makes a set of plots showing off the different behavior of the Prinz model
from Prinz_classes import *
from pylab import *

global_tmin = 0
global_tmax = 20000

# the time domain for the plots below
# just so things look nice, we simulate for 18 s before displaying anything.
tmin = [18000, 18000, 18000, 18000]
tmax = [20000, 20000, 20000, 20000]

#     first check to see if saved data on these files exists, if not then create it.
cell_data_setup("eventually_tonic_cell_config",global_tmax)
cell_data_setup("bursting_cell_config",global_tmax)
cell_data_setup("non_periodic_cell_config",global_tmax)
cell_data_setup("one_spike_burster_cell_config",global_tmax)

# set up the cells
tonic = Ccell.from_data_file("eventually_tonic/cell_data.cPickle")
burster = Ccell.from_data_file('bursting/cell_data.cPickle')
non_periodic = Ccell.from_data_file('non_periodic/cell_data.cPickle')
one_spike_burster = Ccell.from_data_file('one_spike_burster/cell_data.cPickle')


def plot_range(new_tmin,new_tmax,subfig,fignum):
    if new_tmin < global_tmin:
        raise RuntimeError('new_tmin chosen too low... %d < %d' % (new_tmin,global_tmin))
    if new_tmax > global_tmax:
        raise RuntimeError('new_tmax chosen too high... %d > %d' % (new_tmax,global_tmax))
    tmin[subfig] = new_tmin
    tmax[subfig] = new_tmax

    figure(fignum)
    #------- tonic cell ----------
    subplot(221)
    title("Tonic")
    i = 0
    cell = tonic
    ti_min = floor(tmin[i]/cell.dt)
    ti_max = floor(tmax[i]/cell.dt)
    t = cell.t[0:ti_max-ti_min] # just use the time array from the cell we simulated
    v = cell.V_trace()[ti_min:ti_max]
    plot(t,v)
    #------- bursting cell ----------
    subplot(222)
    title("Bursting")
    i = 1
    cell = burster
    ti_min = floor(tmin[i]/cell.dt)
    ti_max = floor(tmax[i]/cell.dt)
    t = cell.t[0:ti_max-ti_min] # just use the time array from the cell we simulated
    v = cell.V_trace()[ti_min:ti_max]
    plot(t,v)
    #------- non-periodic cell ----------
    subplot(223)
    title("Non-Periodic")
    i = 2
    cell = non_periodic
    ti_min = floor(tmin[i]/cell.dt)
    ti_max = floor(tmax[i]/cell.dt)
    t = cell.t[0:ti_max-ti_min] # just use the time array from the cell we simulated
    v = cell.V_trace()[ti_min:ti_max]
    plot(t,v)
    xlabel('Time (ms)')
    ylabel('Voltage (mV)')
    #------- one_spike_burster cell ----------
    subplot(224)
    title("One Spike Bursting")
    i = 3
    cell = one_spike_burster
    ti_min = floor(tmin[i]/cell.dt)
    ti_max = floor(tmax[i]/cell.dt)
    t = cell.t[0:ti_max-ti_min] # just use the time array from the cell we simulated
    v = cell.V_trace()[ti_min:ti_max]
    plot(t,v)

plot_range(18000,20000,0,0)

